Skip to content

Use async def instead of def ... -> Awaitable in typing#7105

Merged
srittau merged 2 commits intopython:masterfrom
sobolevn:patch-128
Feb 2, 2022
Merged

Use async def instead of def ... -> Awaitable in typing#7105
srittau merged 2 commits intopython:masterfrom
sobolevn:patch-128

Conversation

@sobolevn
Copy link
Member

@sobolevn sobolevn commented Feb 2, 2022

Source: https://github.com/python/cpython/blob/187930f74c44e460ba09c60ba5d9bb4fac543d8f/Lib/_collections_abc.py#L206-L240

Why is that important? Because async def is a Coroutine, which is much more than Awaitable. For example, this backfires in #6779

@sobolevn sobolevn mentioned this pull request Feb 2, 2022
@sobolevn
Copy link
Member Author

sobolevn commented Feb 2, 2022

Ok, types.pyi as well.

@github-actions

This comment has been minimized.

1 similar comment
@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2022

Diff from mypy_primer, showing the effect of this PR on open source code:

tornado (https://github.com/tornadoweb/tornado)
+ tornado/gen.py:429: error: Incompatible return value type (got "WaitIterator", expected "AsyncIterator[Any]")
+ tornado/gen.py:429: note: Following member(s) of "WaitIterator" have conflicts:
+ tornado/gen.py:429: note:     Expected:
+ tornado/gen.py:429: note:         def __anext__(self) -> Coroutine[Any, Any, Any]
+ tornado/gen.py:429: note:     Got:
+ tornado/gen.py:429: note:         def __anext__(self) -> Future[Any]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants